package com.enjoyor.soa.traffic.core.tsms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.tsms.domain.Template;
import com.enjoyor.soa.traffic.core.tsms.mapper.ITemplateMapper;
import com.enjoyor.soa.traffic.core.tsms.service.ITemplateExampleService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.pojo.Page;


@Service
@Transactional
@SuppressWarnings("rawtypes")
public class TemplateExampleService implements ITemplateExampleService {

    @Autowired
    private ITemplateMapper templateMapper;

    @Autowired
    private IPubLogMapper pubLogMapper;

    @Override
    public Template select(String id) {
        return templateMapper.selectById(id);
        //return null;
    }
    
    @Override
    public List<Template> selectList(String id, String type, String content){
    	Map<String,Object> paramT = new HashMap<String ,Object>();
    	paramT.put("id", id);
    	paramT.put("type", type);
    	paramT.put("content", content);
    	return templateMapper.selectList(paramT);
    }
    
    @Override
    public Page selectPage(Page page, String timeStart, String timeEnd) {
    	Map<String,String> mapBean = new HashMap<String,String>();
    	mapBean.put("timeStart", timeStart);
    	mapBean.put("timeEnd", timeEnd);
    	page.setMapBean(mapBean);
        return templateMapper.selectPageInfo(page);
    }

    @Override
    public void insert(Template template, String userName) {
        templateMapper.insert(template);
        pubLogMapper.saveNoramlLogInfo(userName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_INSERT.getCode(),
                String.format("添加Template测试表单编号:{%s} 操作成功!", new Object[] { template.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TEMPLATE_TEST_MANAGEMENT.getMessage());
    }

    @Override
    public void edit(Template template, String userName) {
        templateMapper.updateByIdSelective(template);
        pubLogMapper.saveNoramlLogInfo(userName,null, LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_UPDATE.getCode(),
                String.format("修改Template测试表单编号:{%s} 操作成功!", new Object[] { template.getId() }),
                LogInfoDic.LOG_MODULAR_ENUM.TEMPLATE_TEST_MANAGEMENT.getMessage());
    }

    @Override
    public void delete(String id, String userName) {
        templateMapper.deleteById(id);
        pubLogMapper.saveNoramlLogInfo(userName, null,LogInfoDic.LOG_TRANSTYPE_ENUM.TRANSTYPE_DELETE.getCode(),
                String.format("删除Template测试表单编号:{%s} 操作成功!", new Object[] { id }),
                LogInfoDic.LOG_MODULAR_ENUM.TEMPLATE_TEST_MANAGEMENT.getMessage());
    }
}
